Ext.define('GradeView', {
	extend : 'Ext.panel.Panel',
	id : 'GradeView',
	title : '年级管理',
	region : 'center',
	layout : 'border',
	iconCls: 'menu-cusLinkman',

	initComponent : function() {		
		
		this.topbar = new Ext.Toolbar({
					items : [{
								iconCls : 'btn-add',
								text : '添加年级',
								xtype : 'button',
								scope : this,
								handler : this.createRs
							}, {
								iconCls : 'btn-del',
								text : '删除年级',
								xtype : 'button',
								scope : this,
								handler : this.removeSelRs
							}]
				});

		this.gridPanel = new KE.GridPanel({
			region : 'center',
			tbar : this.topbar,
			id : 'GradeGrid',
			url : __ctxPath + "/xskq/listGrade.do",
			fields : ['oid', 'name', 'cnt', {
								name : 'master.fullname',
								mapping : 'master.fullname'
							}, {
								name : 'grade.name',
								mapping : 'grade.name'
							}],
			columns : [{
						header : 'ID',
						dataIndex : 'oid',
						hidden : true
					}, {
						header : '年级名称',
						dataIndex : 'name'					
					}, {
						text : '管理',
						xtype : 'actioncolumn',
						items : [{
									iconCls : 'btn-del',
									tooltip : '删除',
									scope : this,
									handler : function(grid, rowIndex, colIndex) {
										var rec = grid.getStore().getAt(rowIndex);
										this.removeRs(rec.data.oid);
									}
								}, {
									iconCls : 'btn-edit',
									tooltip : '编辑',
									scope : this,
									handler : function(grid, rowIndex, colIndex) {
										var rec = grid.getStore().getAt(rowIndex);
										this.editRs(rec);
									}
								}]
					}]
		});

		this.items = [this.gridPanel];
		this.callParent();
		this.gridPanel.on('rowdblclick', this.rowClick);
	},
	// 重置查询表单
	reset : function() {
		this.searchPanel.getForm().reset();
		Ext.each(this.searchPanel.query('combo'), function(c) {
			c.setValue('');
			c.setRawValue('');
		});
	},
	// 按条件搜索
	search : function() {
		$search({
			searchPanel : this.searchPanel,
			gridPanel : this.gridPanel
		});
	},
	// GridPanel行点击处理事件
	rowClick : function(grid, rec) {
		new GradeForm({
			sid : rec.data.oid
		}).show();
	},
	// 创建记录
	createRs : function() {
		new GradeForm().show();
	},
	// 按ID删除记录
	removeRs : function(id) {
		$postDel({
			url : __ctxPath + '/xskq/multiDelGrade.do',
			ids : id,
			grid : this.gridPanel
		});
	},
	// 把选中ID删除
	removeSelRs : function() {
		$delGridRs({
			url : __ctxPath + '/xskq/multiDelGrade.do',
			grid : this.gridPanel,
			idName : 'oid'
		});
	},
	// 编辑Rs
	editRs : function(record) {
		new GradeForm({
			sid : record.data.oid
		}).show();
	}

});
